package com.oauth.service.application.beans;

import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class MemberApplicationRelation {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long primaryKey;
	
	@Persistent
	private Long memberId;
	
	/**
	 * We are using set because application id's should be unique for given member.
	 */
	@Persistent
	private Set<Long> applicationIdSet;
	
	
	public MemberApplicationRelation(Long pMemberId, Set<Long> pApplicationIdSet) {
		super();
		memberId = pMemberId;
		applicationIdSet = pApplicationIdSet;
	}
	
	public Long getMemberId() {
		return memberId;
	}
	public void setMemberId(Long pMemberId) {
		memberId = pMemberId;
	}
	public Long getPrimaryKey() {
		return primaryKey;
	}
	public void setPrimaryKey(Long pPrimaryKey) {
		primaryKey = pPrimaryKey;
	}
	public Set<Long> getApplicationIdSet() {
		return applicationIdSet;
	}
	public void setApplicationIdSet(Set<Long> pApplicationIdSet) {
		applicationIdSet = pApplicationIdSet;
	}
	
	public void addApplication(Long pApplicationId){
		getApplicationIdSet().add(pApplicationId);
	}
	
	public void removeApplication(Long pApplicationId){
		getApplicationIdSet().remove(pApplicationId);
	}
}
